#include <iostream>
#include "basic/basic.h"
#include "io/io.h"

void test_timer(){
	std::cout << "testTimer " << boost::this_thread::get_id() << std::endl;
}

class TestTimerCls{
public:
	void test(){
		std::cout << "TestTimerCls::test " << boost::this_thread::get_id() << std::endl;
	}
};

class packet_decoder : public eyas::io::packet_decoder_base{
public:
	virtual int32_t advance_recv_buffer(){
		return 64;
	}
	// 收到数据调用
	// return true:数据包完整  false:不完整
	virtual bool decode(eyas::buffer::iobuffer& buffer){
		return true;
	}
	// 数据
	virtual eyas::buffer::iobuffer& data(){

	}
};
int main() {
	{	// 测试并发编程
		eyas::io::init();

		eyas::io::tcp_client_ptr client_ptr = eyas::io::create_tcp_client();

		client_ptr->open("127.0.0.1", 9000, [client_ptr](eyas::io::tcp_connection_ptr const & conn_ptr, const eyas::io::error_code &error){
			if(error){
				// 连接失败
			}else{
				// 连接成功
				conn_ptr->launch<packet_decoder>([](eyas::io::tcp_connection_ptr const & conn_ptr, eyas::buffer::iobuffer & buffer, const boost::system::error_code & error){
					if(error){
						// 连接断开
						return;
					}
					// 处理收到的数据
					// ...
				});
			}
		});
	}
	std::cout << "Enter exit the test." << std::endl;
	getchar();
	return 0;
}
